const app = getApp();

Page({
  data: {
    longitude: '',
    latitude: '',
    isShow: false,
    detailStatus: false,
    status: '',
    markers: [],
    points: [],
    distance: '',
    cost: '',
    city: '',
    tips: {},
    polyline: []
  },
  onLoad() {
    var polylineZip = wx.getStorageSync("polyline");
    if (!polylineZip) {
      wx.showToast({
        title: '系统错误，没有获取到显示的路线数据',
        duration: 2000
      })
    }
    
    var pathCon = JSON.parse(polylineZip);
    console.log(pathCon);
    var coors = pathCon.polyline;
    var points = [];
    for (var i = 2; i < coors.length; i++) {
      coors[i] = coors[i - 2] + coors[i] / 1000000;
      
      if (i % 2 == 0) {
        var point = {};
        point.latitude = coors[i - 2] + coors[i] / 1000000;
      }
      if (i % 2 == 1) {
        point.longitude = coors[i - 2] + coors[i] / 1000000;
        points.push(point);
      }
      
    }
    var zdPIndex = points.length;
    var polyline = [{
      points: points,
      color: "#388bff",
      width: 4
    }];
    var markers = [];
    
    //起点
    markers.push({
      iconPath: "/images/car-wz.png",
      id: 0,
      latitude: points[0].latitude,
      longitude: points[0].longitude,
      width: 35,
      height: 35
    });
    //终点  
    markers.push({
      iconPath: "/images/car-wz2.png",
      id: 0,
      latitude: points[zdPIndex-1].latitude,
      longitude: points[zdPIndex-1].longitude,
      width: 35,
      height: 35
    });
    var pointsI = [];
    pointsI.push(points[0])
    pointsI.push(points[zdPIndex - 1])
    this.setData({ 
      longitude: points[0].longitude,
      latitude: points[0].latitude,
      polyline: polyline,
      distance: pathCon.distance,
      cost: pathCon.time,
      markers: markers,
      points: pointsI
    });
    console.log(polyline)
  }
})